package com.sita.bluetactivity.MyClass;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.sita.bluetactivity.Base.BaseApplication;

/**
 * Created by Jason on 2016/10/24.
 */

public class DaoSingleTon {

    private static final String DATABASE_NAME = "bindvehicle.db";
    private volatile static DaoSingleTon instance;
    private SQLiteDatabase db;
    private DaoMaster daoMaster;
    private DaoSession daoSession;
    private Context context;
    private DaoMaster.DevOpenHelper helper;
    private BindVehicleDao bindVehicle;
    private DaoSingleTon(){
        context = BaseApplication.getContext();
    }
    public static DaoSingleTon getInstance(){
        if (instance ==null){
            synchronized (DaoSingleTon.class){
                instance = new DaoSingleTon();
            }
        }
        return instance;
    }
    public  DaoMaster.DevOpenHelper getHelper(){
        if (helper ==null){
            helper = new DaoMaster.DevOpenHelper(context,DATABASE_NAME,null);
        }
        return helper;
    }
    private SQLiteDatabase getDb(){
        if (db ==null){
            db = getHelper().getWritableDatabase();
        }
        return db;
    }
    private DaoMaster getDaoMaster(){
        if (daoMaster==null){
            daoMaster = new DaoMaster(getDb());
        }
        return daoMaster;
    }
    private DaoSession getDaoSession(){
        if (daoSession==null){
            daoSession = getDaoMaster().newSession();
        }
        return daoSession;
    }
    public BindVehicleDao getBindVehicleDao(){
        if (bindVehicle ==null){
            bindVehicle = getDaoSession().getBindVehicleDao();
        }
        return bindVehicle;
    }
}
